package com.zuokun.aop;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class ProtocolAspect {

    private final ObjectMapper objectMapper = new ObjectMapper();

//    @Around("@annotation(protocol)")
//    public void protocol(ProceedingJoinPoint joinPoint,Protocol protocol) throws Throwable{
//        log.info("开始进行方法参数转对象...");
//        //获取协议名
//        String protocolName = protocol.value();
//
//        //获取当前被拦截方法的数据库操作类型
//        MethodSignature signature = (MethodSignature) joinPoint.getSignature();//方法签名对象
//        Method method = signature.getMethod();
//
//        // 获取原始参数
//        Object[] args = joinPoint.getArgs();
//        if (args.length != 1 || !(args[0] instanceof String)) {
//            throw new IllegalArgumentException("只支持一个String类型参数");
//        }
//
//        // 将 JSON 字符串转为对象
//        Class<?> targetClass = Class.forName(protocolName);
//        Object realArg = objectMapper.readValue((String) args[0], targetClass);
//
//        // 替换参数并调用原方法
//        method.invoke(joinPoint.getTarget(), realArg);
//    }
}
